import pandas as pd
from pandas import DataFrame
from sklearn.cluster import DBSCAN
from sklearn.metrics import calinski_harabasz_score,silhouette_score
import numpy as np
import matplotlib.pyplot as plt

datafile = './文本/货运量_1-16.csv' 
data = pd.DataFrame(pd.read_csv(datafile))
data = data.drop(['机场名'], axis=1)#删除第一列机场名

train = np.array(data) 
dbscan = DBSCAN(eps=5000000,min_samples=1).fit_predict(train)
score = silhouette_score(train,dbscan) #计算轮廓系数
print(score) #输出轮廓系数分数
dbscan2 = DBSCAN(eps=5000000,min_samples=1).fit(train)
score2 = calinski_harabasz_score(train,dbscan2.labels_) #计算CA指数
print(score2) #输出CA指数
plt.scatter(train[:,0],train[:,1],c=dbscan)
plt.title('DBSCAN')
plt.show()